package com.shensi.adminCollect.controller.integral;

import com.shensi.common.core.controller.BaseController;
import com.shensi.common.core.domain.AjaxResult;
import com.shensi.common.core.domain.entity.SysDept;
import com.shensi.common.core.page.TableDataInfo;
import com.shensi.adminCollect.common.utils.poi.ExcelUtil;
import com.shensi.adminCollect.domain.integral.IntegralShopPic;
import com.shensi.adminCollect.service.integral.IIntegralShopPicService;
import com.shensi.adminCollect.service.system.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.shensi.common.core.domain.model.LoginUser;
import com.shensi.common.core.utils.SecurityUtils;

/**
 * 积分商城图片信息Controller
 *
 * @author qujia
 * @date 2021-03-18
 */
@RestController
@RequestMapping("/integral/pic")
public class IntegralShopPicController extends BaseController
{
    @Autowired
    private IIntegralShopPicService integralShopPicService;
    @Autowired
    private ISysDeptService sysDeptService;
    /**
     * 查询积分商城图片信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(IntegralShopPic integralShopPic)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = sysDeptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            integralShopPic.setStationIdList(list);
        }
        startPage();
        List<IntegralShopPic> piclist = integralShopPicService.selectIntegralShopPicList(integralShopPic);
        return getDataTable(piclist);
    }

    /**
     * 导出积分商城图片信息列表
     */
    @GetMapping("/export")
    public AjaxResult export(IntegralShopPic integralShopPic)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = sysDeptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            integralShopPic.setStationIdList(list);
        }
        List<IntegralShopPic> piclist = integralShopPicService.selectIntegralShopPicList(integralShopPic);
        ExcelUtil<IntegralShopPic> util = new ExcelUtil<IntegralShopPic>(IntegralShopPic.class);
        return util.exportExcel(piclist, "pic");
    }

    /**
     * 获取积分商城图片信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(integralShopPicService.selectIntegralShopPicById(id));
    }

    /**
     * 新增积分商城图片信息
     */
    @PostMapping
    public AjaxResult add(@RequestBody IntegralShopPic integralShopPic)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        return toAjax(integralShopPicService.insertIntegralShopPic(integralShopPic));
    }

    /**
     * 修改积分商城图片信息
     */
    @PutMapping
    public AjaxResult edit(@RequestBody IntegralShopPic integralShopPic)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        return toAjax(integralShopPicService.updateIntegralShopPic(integralShopPic));
    }

    /**
     * 删除积分商城图片信息
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(integralShopPicService.deleteIntegralShopPicByIds(ids));
    }
}
